package com.asa;

import java.text.NumberFormat;

import com.asa.hutils.MathHUtils;
import com.asa.utils.Calculate;
import com.asa.utils.MathUtils;
import com.asa.utils.Norm;

public class Client {
	
	public static void main(String[] args) throws Exception {
//		one();
//		two();
//		three();
//		four();
//		five();
//		six();
//		seven();
//		eight();
//		nine();
	
		
		
		
		
		
		test1();
	}







	/**
	 * 计算矩阵的特征向量
	 * @throws Exception
	 */
	private static void nine() throws Exception {
		double[][] a = {
				{1, 2, 3},
				{2, 1, 3},
				{3, 3, 6}
			};
//		double[][] a = {
//	            {1, 2, 3},
//	            {0.5, 1, 2},
//	            {1.0 / 3.0, 0.5, 1}
//	        };
		double[][] juzhengtezhengxiangliang = MathHUtils.juzhengtezhengxiangliang(a);
		//System.out.println("==========结果===========");
		for (int i = 0; i < juzhengtezhengxiangliang.length; i++) {
			for (int j = 0; j < juzhengtezhengxiangliang[i].length; j++) {
				System.out.print(juzhengtezhengxiangliang[i][j]+"      ");
			}
			System.out.println();
		}
	}








	private static void test1() {
//		double[][] a = {
//				{1, 2, 3},
//				{2, 1, 3},
//				{3, 3, 6}
//			};
		double[][] a = {
        {1, 2, 3},
        {0.5, 1, 2},
        {1.0 / 3.0, 0.5, 1}
		};
		double[] r = MathHUtils.juzhengtezhengzhi(a);
		
		//System.out.println(r.length+"==================");
		for (int i = 0; i < r.length; i++) {
			//System.out.println(r[i]);
		}
		//System.out.println(r.length+"==================");
		double[][] asa = new double[a.length][a.length]; 
		for (int j = 0; j < asa.length; j++) {
			for (int k = 0; k < asa.length; k++) {
				asa[j][k] = a[j][k];
			}
		}
		
		for (int j = 0; j < r.length; j++) {
			asa[j][j] = asa[j][j]-r[0];
		}
		for (int i = 0; i < asa.length; i++) {
			for (int j = 0; j < asa.length; j++) {
				System.out.print(asa[i][j]+"     ");
			}
			//System.out.println();
		}

		//System.out.println(r.length+"==================");
		double[] b = new double[a.length-1];
		for (int i = 0; i < b.length; i++) {
			//System.out.println(asa[0][i]);
		}
		//System.out.println("===========================");
		for (int i = 0; i < b.length; i++) {
			b[i] = -asa[0][i];
		}
		double[][] c = new double[a.length-1][a.length-1];
		for (int i = 0; i < c.length; i++) {
			for (int j = 0; j < c.length; j++) {
				c[i][j] = asa[i][j+1];
			}
		}
		for (int i = 0; i < c.length; i++) {
			for (int j = 0; j < c.length; j++) {
				System.out.print(c[i][j]+"         ");
			}
			//System.out.println();
		}
		for (int i = 0; i < b.length; i++) {
			//System.out.println(b[i]);
		}
		
		double[] duoyuanyici = MathUtils.duoyuanyici(c, b);
		for (int i = 0; i < duoyuanyici.length; i++) {
			//System.out.println(duoyuanyici[i]+"       ");
		}
	}

	
	
	
	
	
	
	
	/**
	 * 计算函数的特征值
	 */
	private static void eight() {
		double[][] a = {
				{1, 2, 3},
				{2, 1, 3},
				{3, 3, 6}
			};
		double[] juzhengtezhengzhi = MathHUtils.juzhengtezhengzhi(a);
		
		System.out.println(juzhengtezhengzhi.length+"==================");
		for (int i = 0; i < juzhengtezhengzhi.length; i++) {
			System.out.println(juzhengtezhengzhi[i]);
		}
	}


	/**
	 * 求解矩阵的逆
	 * @throws Exception
	 */
	private static void seven() throws Exception {
		double a[][] = {{1,6,9},{4,2,7},{8,5,3}};
		double[][] juzhengni = MathHUtils.juzhengni(a);
		for (int i = 0; i < juzhengni.length; i++) {
			for (int j = 0; j < juzhengni.length; j++) {
				System.out.print(juzhengni[i][j]+"    ");
			}
			//System.out.println();
		}
	}


	/*
	 *拟合函数
	 */
	private static void six() {
		double[] x = { 0.24, 0.65, 0.95, 1.24, 1.73, 2.01, 2.23, 2.52, 2.77,
				2.99 };
		double[] y = { 0.23, -0.26, -1.10, -0.45, 0.27, 0.10, -0.29, 0.24,
				0.56, 1.00 };
		
//		double[] nihe = Norm.nihe(x, y);
//		for (int i = 0; i < nihe.length; i++) {
//			//System.out.println(nihe[i]);
//		}
		String nihe = Calculate.nihe(x, y);
		//System.out.println(nihe);
	}


	/**
	 * 常微分方程的解值
	 */
	private static void five() {
		double t = 1;
		double x = 2;
		HanShu hanShu = new HanShu() {
			/**
			  *x' = (t*x-x*x)/(t*t)
			  *x(1)=2;
			 */
			@Override
			public double hanshu(double t, double x) {
				// TODO Auto-generated method stub
				return (t*x-x*x)/(t*t);
			}
			
			@Override
			public double hanshu(double x0) {
				// TODO Auto-generated method stub
				return 0;
			}
		};
		double tt = 3;
//		double siJieLongGe = MathUtils.siJieLongGe(t, x,tt , hanShu);
//		
//		//System.out.println(siJieLongGe);
		double hanshuchangweifen = Calculate.hanshuchangweifen(t, x, tt, hanShu);
		//System.out.println(hanshuchangweifen);
	}


	
	/**
	 * 计算函数的积分值
	 */
	private static void four() {
		double a = 0;
		double b =2;
		HanShu hanShu = new HanShu() {
			
			@Override
			public double hanshu(double x0) {
				// TODO Auto-generated method stub
				return x0;
			}

			@Override
			public double hanshu(double t, double x) {
				// TODO Auto-generated method stub
				return 0;
			}
		};
//		double longBeiGe = MathUtils.longBeiGe(a, b, hanShu);
//		//System.out.println(longBeiGe);
		double hanshujifen = Calculate.hanshujifen(a, b, hanShu);
		//System.out.println(hanshujifen);
	}



	private static void three() {
		double[] y = {1,-23,-54,-954};
		double[] x = {5,-7,-6,0};
//		double[] y = {1,1};
//		double[] x = {-1,1};
		double[] hangshuhuoqu = MathUtils.hangshuhuoqu(x, y);
		for (int i = 0; i < hangshuhuoqu.length; i++) {
			//System.out.println(hangshuhuoqu[i]);
		}
		String hanshunihe1 = Calculate.hanshunihe1(x, y);
		//System.out.println(hanshunihe1);
		
		
		
		String hanshunihe2 = Calculate.hanshunihe2(x, y);
		//System.out.println(hanshunihe2);
	}



	/**
	 * 线性方程组的解
	 */
	private static void two() {
		double a[][] = {{0,1},{1,1}};
		double b[] = {1,2};
//		double[] duoyuanyici = MathUtils.duoyuanyici(a,b);
//		for (int i = 0; i < duoyuanyici.length; i++) {
//			//System.out.println(duoyuanyici[i]);
//		}
		
		double[] fangchengzudejie = Calculate.fangchengzudejie(a, b);
		for (int i = 0; i < fangchengzudejie.length; i++) {
			//System.out.println(fangchengzudejie[i]);
		}
	}
	
	
	
	
	/**
	 * 测试一元方程的解
	 */
	private static void one() {
		HanShu hanShu = new HanShu() {
			
			@Override
			public double hanshu(double x) {
				// TODO Auto-generated method stub
				return -(x+20);//*(x+25)*(x+40)*(x+100);
			}

			@Override
			public double hanshu(double t, double x) {
				// TODO Auto-generated method stub
				return 0;
			}
		};
		
		
//		double niudun = MathUtils.niudun(10, hanShu);
//		
//		NumberFormat nf = NumberFormat.getNumberInstance();
//        
//        // 保留两位小数
//        nf.setMaximumFractionDigits(2); 
//		//System.out.println(nf.format(niudun));
		
		double[] hangshujie = Calculate.hangshujie(2, hanShu);
		for (int i = 0; i < hangshujie.length; i++) {
			//System.out.println(hangshujie[i]);
		}
	}
}
